#pragma once
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
#define ok 1
#define error 0
#define overflow -2
#define null 0
#define stack_init_size 100
#define stackincrement 10
typedef int status;
typedef char telemtype;
typedef struct bitnode {
    telemtype data;
    struct bitnode* lchild, * rchild;
}bitnode, * bitree;
typedef bitree selemtype;
typedef struct {
    selemtype* base;
    selemtype* top;
    int stacksize;
}sqstack;
status initstack(sqstack& s)
{
    s.base = (selemtype*)malloc(stack_init_size * sizeof(selemtype));
    if (!s.base)
        exit(overflow);
    s.top = s.base;
    s.stacksize = stack_init_size;
    return ok;
}
status push(sqstack& s, selemtype e)
{
    if (s.top - s.base >= s.stacksize)
    {
        s.base = (selemtype*)realloc(s.base, (s.stacksize + stackincrement) * sizeof(selemtype));
        if (!s.base)
            exit(overflow);
        s.top = s.base + s.stacksize;
        s.stacksize += stackincrement;
    }
    *s.top++ = e;
    return ok;
}
status pop(sqstack& s, selemtype& e)
{
    if (s.top == s.base)
        return error;
    e = *--s.top;
    return ok;
}
status stackempty(sqstack& s)
{
    if (s.top == s.base)
        return 1;
    else
        return 0;
}
status gettop(sqstack s, bitree& p)
{
    if (stackempty(s))
        return error;
    else
    {
        p = *(s.top - 1);
        return ok;
    }
}